package com.wyzz.hr.util.excel;

import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import jxl.Workbook;

public abstract class IReadExcel {

	public IReadExcel() {
	}

	public IReadExcel(File inputFile) {
		setInputFile(inputFile);
	}

	public IReadExcel(String filePath) {
		setInputFile(new File(filePath));
	}

	public List getContent() throws Exception {
		openFile();
		List result = readContent();
		closeFile();
		return result;
	}

	public void openFile() throws Exception {
		inputStream = new FileInputStream(inputFile);
		workbook = Workbook.getWorkbook(inputStream);
	}

	public void closeFile() throws Exception {
		workbook.close();
		workbook = null;
		inputStream.close();
		inputStream = null;
	}

	protected abstract List readContent() throws Exception;

	public File getInputFile() {
		return inputFile;
	}

	public void setInputFile(File inputFile) {
		this.inputFile = inputFile;
	}

	protected FileInputStream inputStream;
	protected Workbook workbook;
	private File inputFile;
}
